//
//  LNCDBManager.m
//
//
//  Created by lanzhongping on 2020/11/12.
//  Copyright © 2020 linktop. All rights reserved.
//

#import "HMDBManager.h"

@implementation HMDBManager
@synthesize db = _db;
@synthesize dbQueue = _dbQueue;



+ (instancetype)instance {
    static HMDBManager *_dbManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
          // 要使用self来调用
        _dbManager = [[self alloc] init];
    });
    return _dbManager;
}
-(NSString *)getDbPath
{
    
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path =  [[paths lastObject]stringByAppendingPathComponent:@"MyDatabase"];
    return path;
}

-(FMDatabase *)db
{
    if (!_db) {
        _db = [FMDatabase databaseWithPath:[self getDbPath]];
        [_db open];
        BOOL encrypt = [_db setKey:@"fuckyou"];
        DebugNSLog(@"加密 %d", encrypt);
      
    }
    return _db;
}

-(FMDatabaseQueue *)dbQueue
{
    if (!_dbQueue) {
        _dbQueue = [FMDatabaseQueue databaseQueueWithPath:[self  getDbPath]];
    }
    return _dbQueue;
}

-(void)dealloc
{
    if (_db) {
        [_db close];
        _db = nil;
    }
}

@end
